<template>
	<div class="app-container">
		<div class="table-wrapper">
			<h4>地下管网易损性计算</h4>
			<el-form :inline="true" ref="queryRef" :rules="rules" label-position="right" :model="params"
				label-width="200px">
				<el-row justify="center">
					<el-col :span="11">
						<el-form-item label="编号：" class="form-item" prop="code">
							<el-input v-model="params.code" placeholder="" :disabled="true" clearable />
						</el-form-item>
					</el-col>
					<el-col :span="11">
						<el-form-item label="年代：" class="form-item" prop="year">
							<el-input v-model="params.year" placeholder="请输入" :disabled="disabled" />
							<!-- <el-select v-model="params.years" placeholder="请选择" class="form-select" :disabled="disabled" clearable>
								<el-option v-for="item in optionList3" :key="item.dictItemCode" :label="item.dictItemName" :value="item.dictItemCode">
								</el-option>
							</el-select> -->
						</el-form-item>
					</el-col>
					<!-- <el-col :span="11">
						<el-form-item label="维护人：" class="form-item" prop="createUserName">
							<el-input v-model="params.createUserName" placeholder="" clearable />
						</el-form-item>
					</el-col> -->
				</el-row>
				<!-- <el-row justify="center">
					<el-col :span="11">
						<el-form-item label="维护人所属单位：" class="form-item" prop="orgName">
							<el-input v-model="params.orgName" placeholder="" clearable />
						</el-form-item>
					</el-col>
					<el-col :span="11">
						<el-form-item label="维护时间:" class="form-item" prop="createTime">
							<el-date-picker v-model="params.createTime" type="date" placeholder="选择日期">
							</el-date-picker>
						</el-form-item>
					</el-col>
				</el-row> -->
				<el-row justify="center">
					<el-col :span="11">
						<el-form-item label="管材：" class="form-item" prop="material">
							<el-select v-model="params.material" placeholder="请选择" class="form-select"
								:disabled="!!route.query.operateType">
								<el-option v-for="item in optionList2" :key="item.dictItemCode" :label="item.dictItemName"
									:value="item.dictItemCode">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="11">
						<el-form-item label="设防情况：" class="form-item" prop="intensity">
							<el-select v-model="params.intensity" placeholder="请选择" class="form-select"
								:disabled="disabled">
								<el-option v-for="item in optionList4" :key="item.dictItemCode" :label="item.dictItemName"
									:value="item.dictItemCode">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row justify="center">
					<el-col :span="11">
						<el-form-item label="场地类别：" class="form-item" prop="siteClassification">
							<el-select v-model="params.siteClassification" placeholder="请选择" class="form-select"
								:disabled="!!route.query.operateType">
								<el-option v-for="item in optionList1" :key="item.dictItemCode" :label="item.dictItemName"
									:value="item.dictItemCode">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="11"></el-col>
				</el-row>
				<el-row v-if="isAdd" justify="end">
					<el-form-item class="bottom-button">
						<!-- <el-button type="primary" @click="showUploadDialog = true">参数导入</el-button> -->
						<el-button type="primary" @click="handleVerify" v-if="!route.query.id">验证</el-button>
						<el-button type="primary" @click="onApply" v-if="route.query.id">计算</el-button>
						<el-button type="primary" @click="onSubmit" v-if="route.query.id">提交</el-button>
					</el-form-item>
				</el-row>
			</el-form>
			<!-- 数据导入弹框 -->
			<import-data v-if="showUploadDialog" v-model="showUploadDialog" ref="uploadDialog" :uploadUrl="uploadUrl"
				downloadFileName="地下管网-简单对应模型计算参数导入.xlsx" @importSuccess="onImport"></import-data>

			<el-form :inline="true" ref="tableRef" :rules="rules" label-position="right" :model="tableFormData">
				<h4>现役管道震害率 λ</h4>
				<el-table class="listTable" ref="multipleTableRef" border :data="tableFormData.tableData2"
					style="width: 100%" :cell-style="{ border: '1px solid #e5ebf7', }"
					:header-cell-style="{ border: '1px solid #e5ebf7', borderLeft: 'none' }">
					<el-table-column header-align="center" align="center" label="接口形式">
						<template #default="scope">
							<el-form-item :prop="`tableData2.${scope.$index}.joint`" :rules="rules.joint">
								<el-select v-model="scope.row.joint" placeholder="请选择" :disabled="scope.row.disabled"
									size="small">
									<el-option v-for="item in optionList5" :key="item.dictItemCode"
										:label="item.dictItemName" :value="item.dictItemCode">
									</el-option>
								</el-select>
							</el-form-item>
						</template>
					</el-table-column>
					<el-table-column header-align="center" align="center" label="管径(mm)" prop="diameter">
						<template #default="scope">
							<el-form-item :prop="`tableData2.${scope.$index}.diameter`" :rules="rules.diameter">
								<el-input v-model="scope.row.diameter" :disabled="scope.row.disabled" size="small"
									type="number"></el-input>
							</el-form-item>
						</template>
					</el-table-column>
					<el-table-column header-align="center" align="center" label="6度区" prop="disasterRate6">
						<template #default="scope">
							<el-form-item :prop="`tableData2.${scope.$index}.disasterRate6`" :rules="rules.disasterRate6">
								<el-input v-model="scope.row.disasterRate6" :disabled="scope.row.disabled" size="small"
									type="number"></el-input>
							</el-form-item>
						</template>
					</el-table-column>
					<el-table-column header-align="center" align="center" label="7度区" prop="disasterRate7">
						<template #default="scope">
							<el-form-item :prop="`tableData2.${scope.$index}.disasterRate7`" :rules="rules.disasterRate7">
								<el-input v-model="scope.row.disasterRate7" :disabled="scope.row.disabled" size="small"
									type="number"></el-input>
							</el-form-item>
						</template>
					</el-table-column>
					<el-table-column header-align="center" align="center" label="8度区" prop="disasterRate8">
						<template #default="scope">
							<el-form-item :prop="`tableData2.${scope.$index}.disasterRate8`" :rules="rules.disasterRate8">
								<el-input v-model="scope.row.disasterRate8" :disabled="scope.row.disabled" size="small"
									type="number"></el-input>
							</el-form-item>
						</template>
					</el-table-column>
					<el-table-column header-align="center" align="center" label="9度区" prop="disasterRate9">
						<template #default="scope">
							<el-form-item :prop="`tableData2.${scope.$index}.disasterRate9`" :rules="rules.disasterRate9">
								<el-input v-model="scope.row.disasterRate9" :disabled="scope.row.disabled" size="small"
									type="number"></el-input>
							</el-form-item>
						</template>
					</el-table-column>
					<el-table-column header-align="center" align="center" label="10度区" prop="disasterRate10">
						<template #default="scope">
							<el-form-item :prop="`tableData2.${scope.$index}.disasterRate10`" :rules="rules.disasterRate10">
								<el-input v-model="scope.row.disasterRate10" :disabled="scope.row.disabled" size="small"
									type="number"></el-input>
							</el-form-item>
						</template>
					</el-table-column>
				</el-table>

				<!-- <el-table class="listTable" ref="multipleTableRef" border :data="tableFormData.tableData2"
					:span-method="objectSpanMethod" style="width: 100%" :cell-style="{ border: '1px solid #e5ebf7', }"
					:header-cell-style="{ border: '1px solid #e5ebf7', borderLeft: 'none' }">
					<el-table-column prop="siteClassification" header-align="center" align="center" label="场地分类" />
					<el-table-column prop="intensity" header-align="center" align="center" label="烈度" />
					<el-table-column header-align="center" align="center" label="管径300 ～ 800mm">
						<el-table-column prop="greyIronPipe" header-align="center" align="center" label="灰口铸铁管">
							<template #default="scope">
								<el-form-item :prop="`tableData2.${scope.$index}.greyIronPipe`" :rules="rules.greyIronPipe">
									<el-input-number v-model="scope.row.greyIronPipe" :disabled="scope.row.disabled" size="small" :min="0"></el-input-number>
								</el-form-item>
							</template>
						</el-table-column>
						<el-table-column header-align="center" align="center" label="水泥管">
							<template #default="scope">
								<el-form-item :prop="`tableData2.${scope.$index}.cementPipe`" :rules="rules.cementPipe">
									<el-input-number v-model="scope.row.cementPipe" :disabled="scope.row.disabled" size="small" :min="0"></el-input-number>
								</el-form-item>
							</template>
						</el-table-column>
						<el-table-column header-align="center" align="center" label="钢管">
							<template #default="scope">
								<el-form-item :prop="`tableData2.${scope.$index}.steelPipe`" :rules="rules.steelPipe">
									<el-input-number v-model="scope.row.steelPipe" :disabled="scope.row.disabled" size="small" :min="0"></el-input-number>
								</el-form-item>
							</template>
						</el-table-column>
						<el-table-column header-align="center" align="center" label="球墨铸铁管">
							<template #default="scope">
								<el-form-item :prop="`tableData2.${scope.$index}.ductileIronPipe`" :rules="rules.ductileIronPipe">
									<el-input-number v-model="scope.row.ductileIronPipe" :disabled="scope.row.disabled" size="small" :min="0"></el-input-number>
								</el-form-item>
							</template>
						</el-table-column>
					</el-table-column>
					<el-table-column header-align="center" align="center" label="管径75 ～ 300mm">
						<el-table-column header-align="center" align="center" label="PVC管">
							<template #default="scope">
								<el-form-item :prop="`tableData2.${scope.$index}.pvcPipe`" :rules="rules.pvcPipe">
									<el-input-number v-model="scope.row.pvcPipe" :disabled="scope.row.disabled" size="small" :min="0"></el-input-number>
								</el-form-item>
							</template>
						</el-table-column>
						<el-table-column header-align="center" align="center" label="PE管">
							<template #default="scope">
								<el-form-item :prop="`tableData2.${scope.$index}.pePipe`" :rules="rules.pePipe">
									<el-input-number v-model="scope.row.pePipe" :disabled="scope.row.disabled" size="small" :min="0"></el-input-number>
								</el-form-item>
							</template>
						</el-table-column>
						<el-table-column header-align="center" align="center" label="PPR管">
							<template #default="scope">
								<el-form-item :prop="`tableData2.${scope.$index}.pprPipe`" :rules="rules.pprPipe">
									<el-input-number v-model="scope.row.pprPipe" :disabled="scope.row.disabled" size="small" :min="0"></el-input-number>
								</el-form-item>
							</template>
						</el-table-column>
					</el-table-column>
				</el-table>

				<el-table class="listTable" ref="multipleTableRef" border :data="tableFormData.tableData3"
					:span-method="objectSpanMethod" style="width: 100%" :cell-style="{ border: '1px solid #e5ebf7', }"
					:header-cell-style="{ border: '1px solid #e5ebf7', borderLeft: 'none' }">
					<el-table-column prop="siteClassification" header-align="center" align="center" label="场地分类" />
					<el-table-column prop="intensity" header-align="center" align="center" label="烈度" />
					<el-table-column header-align="center" align="center" label="管径300 ～ 800mm">
						<el-table-column prop="greyIronPipeValue" header-align="center" align="center" label="灰口铸铁管" />
						<el-table-column prop="cementPipeValue" header-align="center" align="center" label="水泥管" />
						<el-table-column prop="steelPipeValue" header-align="center" align="center" label="钢管" />
						<el-table-column prop="ductileIronPipeValue" header-align="center" align="center" label="球墨铸铁管" />
					</el-table-column>
					<el-table-column header-align="center" align="center" label="管径75 ～ 300mm">
						<el-table-column prop="pvcPipeValue" header-align="center" align="center" label="PVC管" />
						<el-table-column prop="pePipeValue" header-align="center" align="center" label="PE管" />
						<el-table-column prop="pprPipeValue" header-align="center" align="center" label="PPR管" />
					</el-table-column>
				</el-table> -->
			</el-form>
			<div style="margin:20px 0;">
				<h4>计算结果</h4>
				<el-table :data="tableFormData.tableData2" border style="width: 100%">
					<el-table-column prop="disasterRate6State" align="center" label="6度区">
					</el-table-column>
					<el-table-column prop="disasterRate7State" align="center" label="7度区">
					</el-table-column>
					<el-table-column prop="disasterRate8State" align="center" label="8度区">
					</el-table-column>
					<el-table-column prop="disasterRate9State" align="center" label="9度区">
					</el-table-column>
					<el-table-column prop="disasterRate10State" align="center" label="10度区">
					</el-table-column>
				</el-table>
			</div>
			<div style="margin:20px 0;">
				<h4>管线破坏等级划分</h4>
				<el-table :data="tableData" border style="width: 100%">
					<el-table-column prop="phdj" align="center" label="破坏等级">
					</el-table-column>
					<el-table-column prop="jbwh" align="center" label="基本完好">
					</el-table-column>
					<el-table-column prop="qwph" align="center" label="轻微破坏">
					</el-table-column>
					<el-table-column prop="zdph" align="center" label="中等破坏">
					</el-table-column>
					<el-table-column prop="yzph" align="center" label="严重破坏">
					</el-table-column>
					<el-table-column prop="hh" align="center" label="毁坏">
					</el-table-column>
				</el-table>
			</div>
			<!-- 版本查看 -->
			<GetVersion v-if="openDialog" v-model:open="openDialog" @recalculateVersion="recalculateVersion" />
			<el-dialog v-model="dialogVisible" @close="cancle" title="提示" width="500px">
				<p v-for="item in messageList">{{ item.label }}
					<el-popover placement="bottom" title="提示详情" :width="200" trigger="click">
						<template #reference>
							<span style="color: #107ce5;cursor: pointer;">提示详情</span>
						</template>
						<template #default>
							<p v-for="val in item.value">{{ val }}</p>
						</template>
					</el-popover>
				</p>
				<p>&nbsp;</p>
			</el-dialog>
		</div>
	</div>
</template>
 
<script setup>
import { reactive, toRefs } from "vue";
import { ElMessage, ElMessageBox } from 'element-plus'
import {
	getByIdAndType, //查询
	countPseVulnerability, //计算
	savePipelineDamageRate, //保存
	importPipelineDamageRateUrl, // 参数导入
	recalculate, // 获取版本
	somputationSave1,//计算保存
} from "@/api/lifelineVulnerAnalysis/lifelineVulnerAnalysis.js";
import { getValidDictItemsByDictCode } from "@/api/map/disasterDataManagement/lifelineSystemInfo.js";
// 公用方法
import { parseTime } from "@/utils/ruoyi.js";
// 引入导入弹框
import ImportData from "@/components/ImportData";
import GetVersion from './Version';

// 引入store
import useUserStore from '@/store/modules/user';
import useDictStore from '@/store/modules/dict';
// 获取pinia
const userStore = useUserStore();
const dictStore = useDictStore();
// 用户名
const userName = computed(() => userStore.name || '');
// 所属机构名称
const orgName = computed(() => userStore.orgName || '');

// 当前实例
const { proxy } = getCurrentInstance();
// 当前路由
const route = useRoute();
const router = useRouter();

// 打开类型，query为查看
let operateType = computed(() => route.query.operateType || false);
// 是否是新增页，有路由参数是详情页，否则是新增页
let isAdd = computed(() => (route.query.id && route.query.operateType ? false : true));
// 禁用
const disabled = ref(false);

//最多保留N小数 ,N 在 options {decimals: N} 中定义
const positivedecimals = (rule, value, callback) => {
	value = String(value);
	if (
		value.indexOf(".") != -1 &&
		(value.split(".").length > rule.options.decimals ||
			value.split(".")[0] === "" ||
			value.split(".")[1] === "")
	) {
		callback(new Error()); //防止输入多个小数点
	} else if (
		value.indexOf(".") != -1 &&
		value.split(".")[1].length > rule.options.decimals
	) {
		callback(new Error()); //小数点后两位
	} else {
		callback();
	}
};
//验证是否yyyy年份（非必填）
const isYearNotMust = (rule, value, callback) => {
	if (value == '' || value == undefined || value == null) {
		callback();
	} else if (isNaN(Number(value))) {
		callback(new Error('请输入yyyy格式如2022'));
	} else if (value.toString().length != 4) {
		callback(new Error('请输入yyyy格式如2022'));
	} else if (value.toString().indexOf(".") != -1) {
		callback(new Error('请输入yyyy格式如2022'));
	} else {
		callback();
	}
}
const data = reactive({
	// 表单参数
	params: {
		code: "",//编号
		year: "",//年代
		material: "",//管材
		intensity: "", //设防情况
		siteClassification: "",//场地类别
		createTime: parseTime(new Date()), //维护时间
		createUserName: userName.value, //维护人
		orgName: orgName.value, //维护人所属单位
	},
	// 表单验证规则
	rules: {
		material: [
			{ required: true, message: '请选择', trigger: 'change' }
		],
		intensity: [
			{ required: true, message: '请选择', trigger: 'change' }
		],
		siteClassification: [
			{ required: true, message: '请选择', trigger: 'change' }
		],
		year: [
			{
				required: true,
				message: "请输入正确数值",
				validator: isYearNotMust,
				trigger: ["change", "blur"],
			}
		],
		joint: [
			{ required: true, message: "请输入", trigger: "blur" },
			{
				message: "请输入正确数值，最多保留四位小数",
				validator: positivedecimals,
				options: { decimals: 4 },
				trigger: ["change", "blur"],
			},
		],
		diameter: [
			{ required: true, message: "请输入", trigger: "blur" },
			{
				message: "请输入正确数值，最多保留四位小数",
				validator: positivedecimals,
				options: { decimals: 4 },
				trigger: ["change", "blur"],
			},
		],
		disasterRate6: [
			{ required: true, message: "请输入", trigger: "blur" },
			{
				message: "请输入正确数值，最多保留四位小数",
				validator: positivedecimals,
				options: { decimals: 4 },
				trigger: ["change", "blur"],
			},
		],
		disasterRate7: [
			{ required: true, message: "请输入", trigger: "blur" },
			{
				message: "请输入正确数值，最多保留四位小数",
				validator: positivedecimals,
				options: { decimals: 4 },
				trigger: ["change", "blur"],
			},
		],
		disasterRate8: [
			{ required: true, message: "请输入", trigger: "blur" },
			{
				message: "请输入正确数值，最多保留四位小数",
				validator: positivedecimals,
				options: { decimals: 4 },
				trigger: ["change", "blur"],
			},
		],
		disasterRate9: [
			{ required: true, message: "请输入", trigger: "blur" },
			{
				message: "请输入正确数值，最多保留四位小数",
				validator: positivedecimals,
				options: { decimals: 4 },
				trigger: ["change", "blur"],
			},
		],
		disasterRate10: [
			{ required: true, message: "请输入", trigger: "blur" },
			{
				message: "请输入正确数值，最多保留四位小数",
				validator: positivedecimals,
				options: { decimals: 4 },
				trigger: ["change", "blur"],
			},
		],
	},
	disasterRateStateArray: [
		{ label: '基本完好', value: '基本完好' },
		{ label: '轻微破坏', value: '轻微破坏' },
		{ label: '中等破坏', value: '中等破坏' },
		{ label: '严重破坏', value: '严重破坏' },
		{ label: '毁坏', value: '毁坏' }],
	// 表格
	tableFormData: {
		tableData2: [],
		tableData3: []
	},
});
const {
	params,
	rules,
	tableFormData,
} = toRefs(data);

//表格
const multipleTableRef = ref();
const tableData = [
	{
		phdj: '震害率取值范围（处/10KM）',
		jbwh: ' 0',
		qwph: ' 0<λ≤2',
		zdph: ' 2<λ≤5',
		yzph: '5<λ≤12',
		hh: ' λ>12',
	}
]

// 导入弹框是否显示
let showUploadDialog = ref(false);
// 导入数据接口路径
const uploadUrl = ref(importPipelineDamageRateUrl);
// 导入成功回调
const onImport = (response, uploadFile, uploadFiles) => {
	const { code, data } = response;
	if (code == 200 && data) {
		proxy.$modal.msgSuccess('导入数据成功!');
		// 列表数据回显
		tableFormData.value.tableData2 = [...data];
	}
}
// 显示弹框
const openDialog = ref(false)
const handleVerify = () => {
	openDialog.value = true;
}
// 验证
const messageList = ref([]);
const dialogVisible = ref(false);
const cancle = () => {
	dialogVisible.value = false;
}
const recalculateVersion = (version) => {
	openDialog.value = false;
	recalculate({ versionId: version.id, type: '1' }).then(res => {
		if (JSON.stringify(res.data) == '{}') {
			ElMessageBox.confirm(
				'数据通过验证，是否计算？', '提示',
				{
					confirmButtonText: '计算并保存',
					cancelButtonText: '取消',
					type: 'success',
				}
			)
				.then(() => {
					console.log('1111');
					somputationSave1({ versionId: version.id }).then(response => {
						if (response.code == 200) {
							router.push(`/lifelineVulnerAnalysis/lifelineMain?type=1`)
						}
					})
				}).catch(() => { })
		} else {
			const { data } = res;
			messageList.value = [];
			for (let i in data) {
				messageList.value.push({ label: `第${i}行计算参数未填写完整，请补充完整再计算。`, value: data[i] })
			}
			dialogVisible.value = true;
		}
	})
}
// 计算
const onApply = () => {
	proxy.$refs['tableRef'].validate((valid, fields) => {
		if (valid) {
			proxy.$modal.loading('正在努力计算,请耐心等待！');
			let dataFoem = tableFormData.value.tableData2[0];
			let query = {
				id: dataFoem.id,
				material: params.value.material,
				siteClassification: dataFoem.siteClassification,
				joint: dataFoem.joint,
				diameter: dataFoem.diameter,
				disasterRate6: dataFoem.disasterRate6,
				disasterRate6State: dataFoem.disasterRate6State,
				disasterRate7: dataFoem.disasterRate7,
				disasterRate7State: dataFoem.disasterRate7State,
				disasterRate8: dataFoem.disasterRate8,
				disasterRate8State: dataFoem.disasterRate8State,
				disasterRate9: dataFoem.disasterRate9,
				disasterRate9State: dataFoem.disasterRate9State,
				disasterRate10: dataFoem.disasterRate10,
				disasterRate10State: dataFoem.disasterRate10State,
			}
			countPseVulnerability(query).then((res) => {
				proxy.$modal.closeLoading();
				const { code, data } = res;
				if (code === 200 && data) {
					console.log(res.data);
					params.value.material = data.material;
					params.value.siteClassification = data.siteClassification;
					tableFormData.value.tableData2 = [{ ...tableFormData.value.tableData2[0], ...data }];
					proxy.$modal.msgSuccess('计算完成！计算结果未保存，若需保存结果，请计算后点击提交按钮！');
				} else {
					proxy.$modal.msgError('计算失败！');
				}
			}).catch(err => {
				proxy.$modal.closeLoading();
				console.log(err.message);
			});
		}
	})
}
// 保存
const onSubmit = () => {
	proxy.$refs['queryRef'].validate((valid, fields) => {
		if (valid) {
			let dataFoem = tableFormData.value.tableData2[0];
			const query = {
				type: '1',
				upType: '1',
				network1Param: {
					id: dataFoem.id,
					material: params.value.material,
					siteClassification: dataFoem.siteClassification,
					joint: dataFoem.joint,
					diameter: dataFoem.diameter,
					disasterRate6: dataFoem.disasterRate6,
					disasterRate6State: dataFoem.disasterRate6State,
					disasterRate7: dataFoem.disasterRate7,
					disasterRate7State: dataFoem.disasterRate7State,
					disasterRate8: dataFoem.disasterRate8,
					disasterRate8State: dataFoem.disasterRate8State,
					disasterRate9: dataFoem.disasterRate9,
					disasterRate9State: dataFoem.disasterRate9State,
					disasterRate10: dataFoem.disasterRate10,
					disasterRate10State: dataFoem.disasterRate10State,
				}
			}
			proxy.$modal.loading('正在提交,请耐心等待！');
			savePipelineDamageRate(query).then((res) => {
				proxy.$modal.closeLoading();
				const { code, data } = res;
				if (code === 200) {
					proxy.$modal.msgSuccess("保存成功！");
					params.value.material = data.material;
					params.value.siteClassification = data.siteClassification;
					tableFormData.value.tableData2 = [{ ...tableFormData.value.tableData2[0], ...data }];
					// 延迟跳转
					setTimeout(() => {
						router.push('/lifelineVulnerAnalysis/lifelineMain')
					}, 1500)
				}
			}).catch(err => {
				proxy.$modal.closeLoading();
				console.log(err.message);
			});
		} else {
			proxy.$refs['queryRef'].scrollToField(Object.keys(fields)[0])
		}
	})
}
// 获取数据
function getData(query) {
	getByIdAndType(query).then((res) => {
		const { code, data } = res;
		if (code === 200 && data) {
			const { tableEntity, pipelineDamageRateList, upNetworkVo } = data;
			// 基础信息
			params.value.code = tableEntity.code;
			params.value.siteClassification = upNetworkVo.siteClassification;
			params.value.intensity = upNetworkVo.intensity;
			params.value.year = upNetworkVo.year;
			params.value.material = upNetworkVo.material;
			// 维护时间
			const dateTime = new Date()
			params.value.createTime = parseTime(dateTime);
			// 根据id获取用户信息
			params.value.createUserName = userStore.name;
			params.value.orgName = userStore.orgName;
			tableFormData.value.tableData2 = [{ ...upNetworkVo, disabled: operateType.value === 'query' ? true : false }];
			//循环遍历之前加上非空判断
			// if (pipelineDamageRateList.length >= 0) {
			// 	pipelineDamageRateList.forEach((item) => {
			// 		item.disabled = operateType.value === 'query' ? true : false;
			// 		tableFormData.value.tableData2.push({ ...item });
			// 		tableFormData.value.tableData3.push({
			// 			...item,
			// 			// 灰口铸铁管
			// 			greyIronPipeValue: item.greyIronPipeValue || (item.greyIronPipe ? getDamageByValue(item.greyIronPipe) : ''),
			// 			// 水泥管
			// 			cementPipeValue: item.cementPipeValue || (item.cementPipe ? getDamageByValue(item.cementPipe) : ''),
			// 			// 钢管
			// 			steelPipeValue: item.steelPipeValue || (item.steelPipe ? getDamageByValue(item.steelPipe) : ''),
			// 			// 球墨铸铁管
			// 			ductileIronPipeValue: item.ductileIronPipeValue || (item.ductileIronPipe ? getDamageByValue(item.ductileIronPipe) : ''),
			// 			// PVC管
			// 			pvcPipeValue: item.pvcPipeValue || (item.pvcPipe ? getDamageByValue(item.pvcPipe) : ''),
			// 			// PE管
			// 			pePipeValue: item.pePipeValue || (item.pePipe ? getDamageByValue(item.pePipe) : ''),
			// 			// PPR管
			// 			pprPipeValue: item.pprPipeValue || (item.pprPipe ? getDamageByValue(item.pprPipe) : ''),
			// 		});
			// 	});
			// }
		}
	}).catch(err => {
		console.log(err.message);
	});
}
// 根据值获取破坏程度
function getDamageByValue(value) {
	if (value > 12) {
		return '毁坏';
	}
	else if (value > 5) {
		return '严重破坏';
	}
	else if (value > 2) {
		return '中等破坏';
	}
	else if (value > 0) {
		return '轻微破坏';
	}
	else {
		return '基本完好';
	}
}
// 返回字典项值
function getName(arr, code) {
	for (let item of arr) {
		if (item.dictItemCode == code) {
			//字典值
			return item.dictItemName;
		}
	}
}
//字典表查询
const optionList1 = ref([])
const optionList2 = ref([])
const optionList3 = ref([])
const optionList4 = ref([])
const optionList5 = ref([])
/** 获取字典值 */
async function getDictData() {
	await getValidDictItemsByDictCode("smxcdlb").then(response => {
		optionList1.value = response.data; //场地类别
	});
	await getValidDictItemsByDictCode("smxdxgwgc").then(response => {
		optionList2.value = response.data;//管材
	});
	await getValidDictItemsByDictCode("smxjsnd").then(response => {
		optionList3.value = response.data;//建造年代
	});
	await getValidDictItemsByDictCode("smxsfqk").then(response => {
		optionList4.value = response.data;//设防情况
	});
	await getValidDictItemsByDictCode("smxdxgwjkxs").then(response => {
		optionList5.value = response.data;//接口形式
	});
}
// 挂载
onMounted(() => {
	getDictData();
	const id = route.query.id;
	if (id) {
		disabled.value = true;
		// 获取数据
		getData({ id, type: 1 });
	} else {
		disabled.value = false;
	}
});
</script>

<style lang="scss" scoped>
.table-wrapper {
	position: relative;

	h4 {
		font-size: 16px;
		font-weight: bold;
		color: #107ce5;
		text-align: center;
	}

	.listTable {
		margin: 0 0 20px 0;
	}

	.el-table {
		.el-input-number--small {
			width: auto;
		}
	}
}
</style>


